<template>
    <div class="acceptance-registration-pages">
        <commpVxeTable
         :key="commpVxeTableKey"
         :config="dataTableConfig"
         :columns="columnsVxe"
         :formItem="formItem"
         :isCanWrap="true"
         @checkboxChange="checkboxChange"
         ref="acceptanceRegistrationRef"
         >
            <template v-slot:externalOperations="{data}"  >
                <vxe-form-item>
                    <template>
                        <!-- <a-button class="blue-btn" type="primary" @click="approvalFormClick()">批量生成审批表</a-button> -->
                    </template>
                </vxe-form-item>
            </template>
            <template v-slot:operation_fhjmc="{row}" data-desc="环节名称">
                <div v-if="row.fxglx == '新增'">
                    <span v-if="row.fhjmc == '修订确认'">新增确认</span>
                    <span v-else-if="row.fhjmc == '修订审核'">新增审核</span>
                    <span v-else>{{ row.fhjmc }}</span>
                </div>
                <div v-else-if="row.fxglx == '作废'">
                    <span v-if="row.fhjmc == '修订确认'">作废确认</span>
                    <span v-else-if="row.fhjmc == '修订审核'">作废审核</span>
                    <span v-else>{{ row.fhjmc }}</span>
                </div>
                <span v-else>{{ row.fhjmc }}</span>
            </template>
            <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline" class="search-form" >
                    <a-form-item v-if="row.fhjmc !== '宣贯学习'">
                        <a-button class="blue-btn" type="primary" @click="reviseClick(row)" icon="edit">办理</a-button>
                    </a-form-item>
                    <a-form-item v-if="row.fhjmc == '宣贯学习'">
                        <a-button class="green-btn" @click="startLearning(row)" icon="play-square">开始学习</a-button>
                    </a-form-item>
                    <!-- <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="approvalFormClick(row)">生成审批表</a-button>
                    </a-form-item> -->
                    <a-form-item v-if="row.fhjmc == '申请'">
                        <a-button class="red-btn" type="primary" @click="deleteClick(row)" icon="delete">删除</a-button>
                    </a-form-item>
                </a-form>
            </template>
        </commpVxeTable>

        <increase ref="refModel" :addEditParameter="addEditParameter" :viewFlag="true" @successReturn="successReturn" @reviseClick="reviseClick"/>
        <approvalForm ref="approvalFormRef"/>
        <learningTasks ref="learningTasksRef" @successReturn="successReturn"/>
        <learningTasksPromotePublicize ref="learningTasksPromotePublicizeRef" @successReturn="successReturn"/>
        <impactAssessment ref="impactAssessmentRef" @successReturn="successReturn"/>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import assessCheckApi from './service/api.js'
import { deleteZltxwjFlow, ocalityPostAction, queryJobByJobId } from './service/index'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import increase from './increase.vue'
import moment from 'moment'
import approvalForm from './approvalForm.vue'
import blobType from '@/common/blobType'
import learningTasks from './learningTasks'
import learningTasksPromotePublicize from './learningTasksPromotePublicize'
import impactAssessment from './impactAssessment'
  export default {
    components:{
        commpVxeTable,
        increase,
        approvalForm,
        learningTasks,
        impactAssessment,
        learningTasksPromotePublicize,
    },

    data(){
        return{
            addEditParameter:{},
            formItem:[
                {
                    label: '文件名称',
                    model: 'fwjmc',
                },{
                    label: '分类',
                    model: 'ftype',
                },{
                    label: '类型',
                    model: 'fxglx',
                },{
                    label: '申请科室',
                    model: 'fsqks',
                },{
                    label: '环节名称',
                    model: 'fhjmc',
                }

            ],
            columnsVxe:[
                { type: 'checkbox', width: 60 ,fixed: 'left',},
                {
                    title: '申请人', //列头显示文字
                    field: 'fsqr',
                    fixed: 'left',
                    width: 80,
                },{
                    title: '申请科室', //列头显示文字
                    field: 'fsqks',
                },{
                    title: '文件名称',
                    field: 'fwjmc',
                },{
                    title: '分类',
                    field: 'ftype',
                },
                {
                    title: '类型',
                    field: 'fxglx',
                    width: 80,
                },{
                    title: '申请日期',
                    field: 'fsqrq',
                    width: 100,
                },{
                    title: '环节名称',
                    field: 'fhjmc',
                    slots: {
                        default: 'operation_fhjmc',
                    },
                },{
                    title: '待办人',
                    field: 'fdbr',
                    width: 80,
                },
                // {
                //     title: '发送人',
                //     field: 'ffsrmc',
                //     width: 80,
                // },
                {
                    title: '发送时间',
                    field: 'ffssj',
                },{
                    title: '操作',
                    field: 'jobid',
                    slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                  },
                    fixed: 'right',
                    width: 180,
                }],
            dataTableConfig:{
                api: assessCheckApi.zltxwjFlowJobPage,
                rowId: 'jobid',
                paramet:{}
            },
            specifyDateVal:'',
            isSpecifyDate:false,
            numFigure:1,
            numFigureVisible:false,
            currentReplicationId:'',
            selectedRowKeysArr:[],
            commpVxeTableKey: '',
        }
    },

    methods:{
        async dictionaryQuery(val){
            let dataObj = []
            await ocalityPostAction({dictName:val}).then(res=>{
                //console.log('字典的res',res)
                if(res.code == 200){
                    if(res.result.length){
                        dataObj = res.result
                    }

                }
            })
            return dataObj
        },
        checkboxChange(val){//获取当前选择的行
            //console.log('当前选择表格',val)
            this.selectedRowKeysArr = []
            val.forEach(item => {
                this.selectedRowKeysArr.push(item.zltxwjid)
            });
            //console.log(this.selectedRowKeysArr)
        },
        approvalFormClick(val){
            if(val){
                this.$refs.approvalFormRef.getData(val.zltxwjid)
                this.$refs.approvalFormRef.visibleShow = true
            }else{
                if(this.selectedRowKeysArr.length){
                    this.$refs.approvalFormRef.getData(this.selectedRowKeysArr.join(','))
                    this.$refs.approvalFormRef.visibleShow = true
                }else{
                    this.$message.warning('请选择项')
                }
            }
        },
        deleteClick(row){
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                onOk() {
                    deleteZltxwjFlow({zltxwjid: row.zltxwjid}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.commpVxeTableKey = Date.now()
                        }else{
                            that.$message.warning(res.message)
                            that.$refs.acceptanceRegistrationRef.searchEvent()
                        }
                    })
                },
            });
        },
        successReturn(){
            this.$refs.acceptanceRegistrationRef.searchEvent()
        },

        handleOk(val,id){
            if(val && !id){
                this.$refs.acceptanceRegistrationRef.resetEvent()
            }else if(val && id){
                this.requestParams = {
                    ...this.requestParams,
                    renovate:true,
                }
            }

        },
        //编辑
        reviseClick(val){
            queryJobByJobId({jobid: val.jobid}).then(res=>{
                if(res.code == 200){
                    let data = res.result.zltxwj
                    let node = ''
                    if(data.fxglx == '新增'){
                        if(res.result.nextNode == '修订确认'){
                            node = '新增确认'
                        } else if(res.result.nextNode == '修订审核'){
                            node = '新增审核'
                        } else {
                            node = res.result.nextNode
                        }
                    } else if(data.fxglx == '作废'){
                        if(res.result.nextNode == '修订确认'){
                            node = '作废确认'
                        } else if(res.result.nextNode == '修订审核'){
                            node = '作废审核'
                        } else {
                            node = res.result.nextNode
                        }
                    }
                    this.addEditParameter = {
                        id:val.zltxwjid,
                        isDisabled:res.result.job.fhjmc=='申请'?true:false,
                        impactAssessmentShow: (res.result.job.fhjmc=='宣贯效果评价'||res.result.job.fhjmc=='实施发布' ||res.result.job.fhjmc=='文件实施')?true:false,
                        jobid: res.result.job.id,
                        fblzt: res.result.job.fblzt,
                        fthyj: res.result.job.fthyj,
                        fhjmc: res.result.job.fhjmc,
                        zltxwjid: data.id,
                        fsqrq: data.fsqrq?moment(data.fsqrq).format('YYYY-MM-DD'):'',
                        fssrq: data.fssrq?moment(data.fssrq).format('YYYY-MM-DD'):'',
                        fscrq: data.fscrq?moment(data.fscrq).format('YYYY-MM-DD'):'',
                        fwjmc: data.fwjmc,
                        ftype: data.ftype,
                        ftypeid: data.ftypeid,
                        forder: data.forder,
                        fwjbh: data.fwjbh,
                        fxgcs: data.fxgcs,
                        fskbb: data.fskbb,
                        fwjlx: data.fwjlx,
                        fwjlj: data.fwjlj,
                        fzt: data.fzt,
                        fsqr: data.fsqr,
                        fsqks: data.fsqks,
                        fxglx: data.fxglx ? data.fxglx : '修订',
                        fxdly: data.fxdly,
                        fqcsm: data.fqcsm,

                        // nextNodeDbrList: res.result.nextNodeDbrList,
                        nextNode: (data.fxglx == '新增' || data.fxglx == '作废')?node:(res.result.nextNode?res.result.nextNode:''),
                        nextNodeDbr: res.result.nextNodeDbrList&&res.result.nextNodeDbrList.length?res.result.nextNodeDbrList[res.result.nextNodeDbrList.length - 1].dbr:'',
                        fxgxxryid: data.fxgxxryid,
                        fxgxgpj: data.fxgxgpj,
                        ffsr: data.ffsr,
                        ffssj: data.ffssj,
                        fblr: data.fblr,
                        dbrid: [],
                        opinion: '',//办理意见
                        smgflag: '否',//是否发送短信
                    }
                    if(res.result.job.fhjmc == '宣贯效果评价' || res.result.job.fhjmc == '实施发布'){
                        // //console.log('当前环节=============',res.result.job.fhjmc)
                        // this.$refs.impactAssessmentRef.getData(this.addEditParameter)
                        // this.$refs.impactAssessmentRef.visible = true
                        // return
                    }
                    this.$refs.refModel.visibleShow = true
                    this.$refs.refModel.spinning = true
                    this.$aSpinningKey = true
                }else{
                    this.$message.warning(res.message)
                }
            })


        },
        // 开始学习
        startLearning(row){
            queryJobByJobId({jobid: row.jobid}).then(res=>{
                if(res.code == 200){
                    let data = res.result.zltxwj
                    let item = {}
                    item = {
                        id:row.zltxwjid,
                        isDisabled:res.result.job.fhjmc=='申请'?true:false,
                        jobid: res.result.job.id,
                        fblzt: res.result.job.fblzt,
                        fthyj: res.result.job.fthyj,
                        fhjmc: res.result.job.fhjmc,
                        zltxwjid: data.id,
                        fsqrq: data.fsqrq?moment(data.fsqrq).format('YYYY-MM-DD'):'',
                        fssrq: data.fssrq?moment(data.fssrq).format('YYYY-MM-DD'):'',
                        fscrq: data.fscrq?moment(data.fscrq).format('YYYY-MM-DD'):'',
                        fwjmc: data.fwjmc,
                        ftype: data.ftype,
                        ftypeid: data.ftypeid,
                        forder: data.forder,
                        fwjbh: data.fwjbh,
                        fxgcs: data.fxgcs,
                        fskbb: data.fskbb,
                        fwjlx: data.fwjlx,
                        fwjlj: data.fwjlj,
                        fzt: data.fzt,
                        fsqr: data.fsqr,
                        fsqks: data.fsqks,
                        fxglx: data.fxglx ? data.fxglx : '修订',
                        fxdly: data.fxdly,
                        fqcsm: data.fqcsm,

                        // nextNodeDbrList: res.result.nextNodeDbrList,
                        fxgxxryid: data.fxgxxryid,
                        fxgxgpj: data.fxgxgpj,
                        ffsr: data.ffsr,
                        ffssj: data.ffssj,
                        fblr: data.fblr,
                        dbrid: [],
                        opinion: '',//办理意见
                        smgflag: '否',//是否发送短信
                    }
                    if(data.fxglx == '宣贯培训'){
                        this.$refs.learningTasksPromotePublicizeRef.getData({...item,funIndex:0,disabled:true,title:'查看'},[])
                        this.$refs.learningTasksPromotePublicizeRef.visibleShow = true
                    }else{
                        this.$refs.learningTasksRef.getData({...item,funIndex:0,disabled:true,title:'查看'},[])
                        this.$refs.learningTasksRef.visibleShow = true
                    }
                }else{
                    this.$message.warning(res.message)
                }
            })
        },

        AddHandleOk(){
            this.$refs.acceptanceRegistrationRef.resetEvent()
        },
    },

  }
</script>
<style lang="less">
.acceptance-registration-pages{
    .select-date-box{
        display: flex;
        flex-direction: column;
        span{
            color: #f5222d;
            font-size: 14px;
        }
    }
    .modal-btn-box{
        .ant-form-item-control{
            width: 175px !important;
        }
    }

}
</style>
<style scoped >
.observer-lbrary-pages{
    background: #fff;
}
.btn-box{
    display: flex;
    justify-content: flex-end;
}
.blue-btn{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
}
.red-btn{
    border: 1px solid #ed5565 !important;
    background-color: #ed5565 !important;
}




</style>
